home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / c / mkid.lha / src / init.c < prev    next >
C/C++ Source or Header  |  1991-02-01  |  1KB  |  51 lines

  1. /* Copyright (c) 1986, Greg McGary */
  2. static char sccsid[] = "@(#)init.c    1.1 86/10/09";
  3.  
  4. #include    "id.h"
  5. #include    "string.h"
  6. #include    <stdio.h>
  7. #include    "extern.h"
  8.  
  9. FILE *
  10. initID(idFile, idhp, idArgs)
  11.     char        *idFile;
  12.     struct idhead    *idhp;
  13.     struct idarg    **idArgs;
  14. {
  15.     FILE        *idFILE;
  16.     register int    i;
  17.     register char    *strings;
  18.     register struct idarg    *idArg;
  19.  
  20.     if ((idFILE = fopen(idFile, "r")) == NULL)
  21.         return NULL;
  22.  
  23.     fseek(idFILE, 0L, 0);
  24.     fread(idhp, sizeof(struct idhead), 1, idFILE);
  25.     if (!strnequ(idhp->idh_magic, IDH_MAGIC, sizeof(idhp->idh_magic))) {
  26.         fprintf(stderr, "%s: Not an id file: `%s'\n", MyName, idFile);
  27.         exit(1);
  28.     }
  29.     if (idhp->idh_vers != IDH_VERS) {
  30.         fprintf(stderr, "%s: ID version mismatch (want: %d, got: %d)\n", MyName, IDH_VERS, idhp->idh_vers);
  31.         exit(1);
  32.     }
  33.  
  34.     fseek(idFILE, idhp->idh_argo, 0);
  35.     strings = malloc(i = idhp->idh_namo - idhp->idh_argo);
  36.     fread(strings, i, 1, idFILE);
  37.     idArg = *idArgs = (struct idarg *)calloc(idhp->idh_pthc, sizeof(struct idarg));
  38.     for (i = 0; i < idhp->idh_argc; i++) {
  39.         if (*strings == '+' || *strings == '-')
  40.             goto skip;
  41.         idArg->ida_flags = (*strings) ? 0 : IDA_BLANK;
  42.         idArg->ida_arg = strings;
  43.         idArg->ida_next = idArg + 1;
  44.         idArg++;
  45.     skip:
  46.         while (*strings++)
  47.             ;
  48.     }
  49.     return idFILE;
  50. }
  51.